package collections2;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;

public class Birthday {
	public static void main(String[] args) throws ParseException {
	SimpleDateFormat myFormatter = new SimpleDateFormat("MM-dd");  
    String clidate = "02-22";  
    Calendar cToday = Calendar.getInstance(); // 存今天  
    Calendar cBirth = Calendar.getInstance(); // 存生日  
    cBirth.setTime(myFormatter.parse(clidate)); // 设置生日  
    cBirth.set(Calendar.YEAR, cToday.get(Calendar.YEAR)); // 修改为本年  
    int days;   
    if (cBirth.get(Calendar.DAY_OF_YEAR) < cToday.get(Calendar.DAY_OF_YEAR)){  
        // 生日已经过了，要算明年的了  
        days = cToday.getActualMaximum(Calendar.DAY_OF_YEAR) - cToday.get(Calendar.DAY_OF_YEAR);  
        days += cBirth.get(Calendar.DAY_OF_YEAR);  
    } else {  
        // 生日还没过  
        days = cBirth.get(Calendar.DAY_OF_YEAR) - cToday.get(Calendar.DAY_OF_YEAR);  
    }  
    // 输出结果  
    if (days == 0) {  
        System.out.println("今天生日");  
    } else {  
        System.out.println("距离生日还有：" + days + "天");  
    }  
	}
}